package dao;

import java.util.List;

import model.OrderImpl;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;


public class OrderDao{
	
	private HibernateTemplate	hibernateTemplate;
	
	
	public void setSessionFactory( SessionFactory sessionFactory ) {
		this.hibernateTemplate = new HibernateTemplate( sessionFactory );
	}
	
	public Long addOrder(OrderImpl order){
		return ( Long ) hibernateTemplate.save( order );
	}
	
	public OrderImpl getOrder(Long id){
		return ( OrderImpl ) hibernateTemplate.get( OrderImpl.class, id );
	}
	
	public void update(OrderImpl order){
		hibernateTemplate.merge( order );
	}
	
	@SuppressWarnings( "unchecked" )
	public List<OrderImpl> getOrders(){
		return hibernateTemplate.loadAll( OrderImpl.class );
	}
}
